<?php
// 测试MySQL连接
$host = '127.0.0.1';
$port = 3306;
$database = 'qiandao';
$username = 'root';
$password = 'root';

try {
    $dsn = "mysql:host={$host};port={$port};charset=utf8mb4";
    $pdo = new PDO($dsn, $username, $password);
    echo "✓ MySQL连接成功\n";
    
    // 检查数据库是否存在
    $stmt = $pdo->query("SHOW DATABASES LIKE '{$database}'");
    if ($stmt->rowCount() > 0) {
        echo "✓ 数据库 '{$database}' 已存在\n";
        
        // 连接到数据库
        $pdo = new PDO("mysql:host={$host};port={$port};dbname={$database};charset=utf8mb4", $username, $password);
        
        // 检查表是否存在
        $stmt = $pdo->query("SHOW TABLES");
        $tables = $stmt->fetchAll(PDO::FETCH_COLUMN);
        
        if (count($tables) > 0) {
            echo "✓ 数据库中有 " . count($tables) . " 个表\n";
            echo "表列表:\n";
            foreach ($tables as $table) {
                echo "  - {$table}\n";
            }
        } else {
            echo "✗ 数据库中没有表，需要执行迁移\n";
        }
    } else {
        echo "✗ 数据库 '{$database}' 不存在，需要创建\n";
    }
} catch (PDOException $e) {
    echo "✗ 数据库连接失败: " . $e->getMessage() . "\n";
}

